from . import rest
from app import mongo
from flask import jsonify


@rest.route("/hello/<name>")
def hello(name):
    return "hello " + name;


@rest.route("/mongotest")
def mongotest():
    prod = mongo.db.product.find()
    print(prod)
    res = []
    for x in prod:
        res.append(x)
        print(x)
    return jsonify(res)


@rest.route("/mongotest/add")
def addjson():
    """
    添加到数据库
    :return: _id
    """
    json = {"age": 33, "name": 'chenzhiling'}
    id = mongo.db.product.insert(json)
    return str(id)
